package pe.edu.upc.xcode.food.rest;

import java.util.Date;

import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import pe.edu.upc.xcode.food.domain.Categoria;
import pe.edu.upc.xcode.food.domain.Local;
import pe.edu.upc.xcode.food.domain.Restaurant;
import pe.edu.upc.xcode.food.service.RestaurantService;

@Path("/restaurantes")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })

public class RestaurantWS {

	@Autowired
	private  RestaurantService restaurantService;

	private Gson gson = new Gson();

	@GET
	public Response findAll() {
		return null;// Response.ok(gson.toJson(restaurantService.findAll())).build();
	}

	@POST
	public Response save(String json ) {				
		
		
		try {
			System.out.println("esteeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"+json);
				
			Restaurant restaurant = gson.fromJson(json, Restaurant.class);
			restaurantService.save(restaurant);					
			
			
		} catch (Exception e) {
			System.out.println(e);
			return Response.status(Status.INTERNAL_SERVER_ERROR)
					.entity("Error al guardar el Restaurante").build();
		}
		return Response.ok().build();
	}
	
	
	

	
}
